//
//  String+Extension.swift
//  LYOnlineBanking
//
//  Created by 李永彬 on 2025/7/22.
//

import UIKit


extension String {
    static func stringFormat(_ numberString: String) -> String {
        if let decimal = Decimal(string: numberString) {
            let formatter = NumberFormatter()
            formatter.numberStyle = .decimal
            formatter.minimumFractionDigits = 0
            formatter.maximumFractionDigits = 3
            
            if let formattedString = formatter.string(from: decimal as NSNumber) {
                
                return formattedString
            }
        }
        
        return numberString
    }
    
    static func maskCharacters(input: String) -> String {
        guard input.count >= 6 else {
            return input // 如果字符串长度不足6，返回原字符串
        }
        
        var characters = Array(input)
        for i in 2..<6 { // 注意：Swift字符串索引从0开始，所以3~6对应2..<6
            if i < characters.count {
                characters[i] = "*"
            }
        }
        return String(characters)
    }
}
